using System;

namespace CoreEx.Common.Cache
{
    /// <summary>
    /// Represents a cached object that is lazily initialized
    /// </summary>
    /// <typeparam name="TValue">The type of object that this cache represents.</typeparam>
    public interface ILazyCachedValue<TValue> : ILifeSpan
    {
        /// <summary>
        /// Returns the cached value.
        /// </summary>
        /// <param name="initializer">The <see cref="Func{TResult}"/> delegate that is executed if the current value is not valid.</param>
        /// <returns><typeparamref name="TValue"/></returns>
        TValue GetValue(Func<TValue> initializer);
        
        /// <summary>
        /// Invalidates the cache and causes the initializer delegate 
        /// passed to the <see cref="GetValue"/> method to execute.
        /// </summary>
        void Invalidate();
    }
}